package com.biz.primus.app.rest.controller.member;

import com.biz.primus.app.rest.controller.base.RestBaseController;
import com.biz.primus.app.rest.feign.member.MemberFeignClient;
import com.biz.primus.base.support.rest.vo.JsonResult;
import com.biz.primus.base.global.GlobalParams;
import com.biz.primus.model.member.vo.NoticeVo;
import com.biz.primus.model.member.vo.request.NoticePageRequestVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 消息列表
 * @author jun.liu
 * @usage
 * @reviewer
 * @since 2017年11月3日
 */
@RestController
@RequestMapping("/users")
public class MemberNoticeController extends RestBaseController {

    private final MemberFeignClient memberFeignClient;

    @Autowired
    public MemberNoticeController(MemberFeignClient memberFeignClient) {
        this.memberFeignClient = memberFeignClient;
    }

    /**
     * 获取所有消息
     */
    @ApiOperation(value = "获取所有消息", response = NoticeVo.class, responseContainer = "list")
    @GetMapping("/allnotice")
    //
    public JsonResult getAllNotice(GlobalParams gp, @RequestBody NoticePageRequestVo reqVo) {
        reqVo = buildRequest(gp, reqVo);
        List<NoticeVo> resp = memberFeignClient.getAllNoticeRo(reqVo);
        return new JsonResult(resp);
    }

    /**
     * 快喝地图页上小喇叭的内容,(未读消息)
     */
    @ApiOperation(value = "快喝地图页上小喇叭的内容,(未读消息)", response = NoticeVo.class, responseContainer = "list")
    @GetMapping("/remaidnoticetitle")
    public JsonResult getRemaidNoticeTitle(GlobalParams gp,  @RequestBody NoticePageRequestVo req) {
        req = buildRequest(gp, req);
        // 未登录不返回数据
        if (req.getUserId() == null) {
            return new JsonResult();
        }
        List<NoticeVo> resp = memberFeignClient.getUserRemainNotices(req);
        return new JsonResult(resp);
    }
}
